<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>JS笔记集 | MrLee の Blog</title><meta name="keywords" content="JS随笔"><meta name="author" content="MrLee"><meta name="copyright" content="MrLee"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="JS1.在应用中添加 当前时间 方法12345678function runClock()&amp;#123;	theTime &#x3D; window.setTimeout(&quot;runClock()&quot;, 50);	var now				&#x3D; new Date();	var dateValue		&#x3D; now.toLocaleDateString();	var timeValue		&#x3D; now.to">
<meta property="og:type" content="article">
<meta property="og:title" content="JS笔记集">
<meta property="og:url" content="https://amasmrlee.gitee.io/2021/04/16/JS%E7%AC%94%E8%AE%B0/index.html">
<meta property="og:site_name" content="MrLee の Blog">
<meta property="og:description" content="JS1.在应用中添加 当前时间 方法12345678function runClock()&amp;#123;	theTime &#x3D; window.setTimeout(&quot;runClock()&quot;, 50);	var now				&#x3D; new Date();	var dateValue		&#x3D; now.toLocaleDateString();	var timeValue		&#x3D; now.to">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg">
<meta property="article:published_time" content="2021-04-16T01:00:00.000Z">
<meta property="article:modified_time" content="2021-09-06T08:44:28.370Z">
<meta property="article:author" content="MrLee">
<meta property="article:tag" content="JS随笔">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="https://amasmrlee.gitee.io/2021/04/16/JS%E7%AC%94%E8%AE%B0/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//fonts.googleapis.com" crossorigin=""/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Titillium+Web&amp;display=swap" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"search.xml","languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: {"defaultEncoding":2,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"簡"},
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'mediumZoom',
  Snackbar: {"chs_to_cht":"你已切换为繁体","cht_to_chs":"你已切换为简体","day_to_night":"你已切换为深色模式","night_to_day":"你已切换为浅色模式","bgLight":"#49b1f5","bgDark":"#121212","position":"bottom-left"},
  source: {
    jQuery: 'https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js',
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
    },
    fancybox: {
      js: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js',
      css: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: true,
  isanchor: true
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = { 
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2021-09-06 16:44:28'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          const isDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches
          const isLightMode = window.matchMedia('(prefers-color-scheme: light)').matches
          const isNotSpecified = window.matchMedia('(prefers-color-scheme: no-preference)').matches
          const hasNoSupport = !isDarkMode && !isLightMode && !isNotSpecified

          if (t === undefined) {
            if (isLightMode) activateLightMode()
            else if (isDarkMode) activateDarkMode()
            else if (isNotSpecified || hasNoSupport) {
              const now = new Date()
              const hour = now.getHours()
              const isNight = hour <= 6 || hour >= 18
              isNight ? activateDarkMode() : activateLightMode()
            }
            window.matchMedia('(prefers-color-scheme: dark)').addListener(function (e) {
              if (saveToLocal.get('theme') === undefined) {
                e.matches ? activateDarkMode() : activateLightMode()
              }
            })
          } else if (t === 'light') activateLightMode()
          else activateDarkMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const fontSizeVal = saveToLocal.get('global-font-size')
    if (fontSizeVal !== undefined) {
      document.documentElement.style.setProperty('--global-font-size', fontSizeVal + 'px')
    }
    })(window)</script><meta name="generator" content="Hexo 5.4.0"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="author-avatar"><img class="avatar-img" data-lazy-src="/img/avatar/avatar.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/archives/"><div class="headline">文章</div><div class="length-num">34</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/tags/"><div class="headline">标签</div><div class="length-num">35</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/categories/"><div class="headline">分类</div><div class="length-num">14</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">MrLee の Blog</a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">JS笔记集</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="fa-fw post-meta-icon far fa-calendar-alt"></i><span class="post-meta-label">发表于</span><time datetime="2021-04-16T01:00:00.000Z" title="undefined 2021-04-16 09:00:00">2021-04-16</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/JS/">JS</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">2.6k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>13分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="JS笔记集"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h2 id="JS"><a href="#JS" class="headerlink" title="JS"></a>JS</h2><h3 id="1-在应用中添加-当前时间-方法"><a href="#1-在应用中添加-当前时间-方法" class="headerlink" title="1.在应用中添加 当前时间 方法"></a>1.在应用中添加 <strong>当前时间</strong> 方法</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">runClock</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">	theTime = <span class="built_in">window</span>.setTimeout(<span class="string">&quot;runClock()&quot;</span>, <span class="number">50</span>);</span><br><span class="line">	<span class="keyword">var</span> now				= <span class="keyword">new</span> <span class="built_in">Date</span>();</span><br><span class="line">	<span class="keyword">var</span> dateValue		= now.toLocaleDateString();</span><br><span class="line">	<span class="keyword">var</span> timeValue		= now.toLocaleTimeString();</span><br><span class="line">	<span class="keyword">var</span> datetimeValue	= <span class="string">&#x27;當前時間：&#x27;</span> + dateValue + <span class="string">&#x27; &#x27;</span> + timeValue;</span><br><span class="line">	<span class="built_in">document</span>.all.nowtime.innerHTML = datetimeValue;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>  调用方法：  </p>
<p>  <img src= "/img/loading.gif" data-lazy-src="/img/article_img/20190807140611686_718.png" alt="调用方法">  </p>
<h3 id="2-时间倒计时功能："><a href="#2-时间倒计时功能：" class="headerlink" title="2.时间倒计时功能："></a>2.时间倒计时功能：</h3><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line">HTML代码：</span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">&quot;CountMsg&quot;</span> <span class="attr">class</span>=<span class="string">&quot;HotDate&quot;</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">span</span> <span class="attr">id</span>=<span class="string">&quot;t_d&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">span</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">span</span> <span class="attr">id</span>=<span class="string">&quot;t_h&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">span</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">span</span> <span class="attr">id</span>=<span class="string">&quot;t_m&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">span</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">span</span> <span class="attr">id</span>=<span class="string">&quot;t_s&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">span</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"></span><br><span class="line">js代码：</span><br><span class="line">    <span class="tag">&lt;<span class="name">script</span> <span class="attr">type</span>=<span class="string">&quot;text/javascript&quot;</span>&gt;</span></span><br><span class="line"><span class="javascript">        <span class="comment">//高考倒计时</span></span></span><br><span class="line"><span class="javascript">        <span class="function"><span class="keyword">function</span> <span class="title">getRTime</span>(<span class="params"></span>) </span>&#123;</span></span><br><span class="line"><span class="javascript">            <span class="keyword">var</span> EndTime = <span class="keyword">new</span> <span class="built_in">Date</span>(<span class="string">&quot;2019/12/21 23:55:00&quot;</span>); <span class="comment">//截止时间</span></span></span><br><span class="line"><span class="javascript">            <span class="keyword">var</span> NowTime = <span class="keyword">new</span> <span class="built_in">Date</span>();</span></span><br><span class="line"><span class="javascript">            <span class="keyword">var</span> t = EndTime.getTime() - NowTime.getTime();</span></span><br><span class="line"><span class="javascript">            <span class="keyword">var</span> d = <span class="built_in">Math</span>.floor(t / <span class="number">1000</span> / <span class="number">60</span> / <span class="number">60</span> / <span class="number">24</span>);</span></span><br><span class="line"><span class="javascript">            <span class="keyword">var</span> h = <span class="built_in">Math</span>.floor(t / <span class="number">1000</span> / <span class="number">60</span> / <span class="number">60</span> % <span class="number">24</span>);</span></span><br><span class="line"><span class="javascript">            <span class="keyword">var</span> m = <span class="built_in">Math</span>.floor(t / <span class="number">1000</span> / <span class="number">60</span> % <span class="number">60</span>);</span></span><br><span class="line"><span class="javascript">            <span class="keyword">var</span> s = <span class="built_in">Math</span>.floor(t / <span class="number">1000</span> % <span class="number">60</span>);</span></span><br><span class="line"></span><br><span class="line"><span class="javascript">            <span class="built_in">document</span>.getElementById(<span class="string">&quot;t_d&quot;</span>).innerHTML = d + <span class="string">&quot; 天&quot;</span>;</span></span><br><span class="line"><span class="javascript">            <span class="built_in">document</span>.getElementById(<span class="string">&quot;t_h&quot;</span>).innerHTML = h + <span class="string">&quot; 时&quot;</span>;</span></span><br><span class="line"><span class="javascript">            <span class="built_in">document</span>.getElementById(<span class="string">&quot;t_m&quot;</span>).innerHTML = m + <span class="string">&quot; 分&quot;</span>;</span></span><br><span class="line"><span class="javascript">            <span class="built_in">document</span>.getElementById(<span class="string">&quot;t_s&quot;</span>).innerHTML = s + <span class="string">&quot; 秒&quot;</span>;</span></span><br><span class="line">        &#125;</span><br><span class="line"><span class="javascript">        <span class="built_in">setInterval</span>(getRTime, <span class="number">1000</span>);</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br></pre></td></tr></table></figure>

<h3 id="3-数字计时功能："><a href="#3-数字计时功能：" class="headerlink" title="3.数字计时功能："></a>3.数字计时功能：</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">HTML代码：  </span><br><span class="line">&lt;input type=<span class="string">&quot;text&quot;</span> id=<span class="string">&quot;txt&quot;</span> disabled&gt;  </span><br><span class="line"></span><br><span class="line">js代码：  </span><br><span class="line"><span class="keyword">var</span> c=<span class="number">0</span></span><br><span class="line"><span class="keyword">var</span> t</span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">timedCount</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">    <span class="built_in">document</span>.getElementById(<span class="string">&#x27;txt&#x27;</span>).value=c</span><br><span class="line">    c=c+<span class="number">1</span></span><br><span class="line">    t=<span class="built_in">setTimeout</span>(<span class="string">&quot;timedCount()&quot;</span>,<span class="number">1000</span>)</span><br><span class="line">    <span class="keyword">if</span>(c == <span class="number">11</span>) &#123;    <span class="comment">//当数字到 10 时，计时终止</span></span><br><span class="line">        stopCount()</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">stopCount</span>(<span class="params"></span>)</span>&#123;    <span class="comment">//计时终止器</span></span><br><span class="line">    <span class="built_in">clearTimeout</span>(t)</span><br><span class="line">&#125;</span><br><span class="line">timedCount()</span><br></pre></td></tr></table></figure>

<h3 id="4-遇到一行字数太多显示不完，可以使用以下方法："><a href="#4-遇到一行字数太多显示不完，可以使用以下方法：" class="headerlink" title="4.遇到一行字数太多显示不完，可以使用以下方法："></a>4.遇到一行字数太多显示不完，可以使用以下方法：</h3><p>以span标签为例：<br>style样式：  </p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-tag">span</span>&#123;</span><br><span class="line">    <span class="attribute">word-break</span>:normal;</span><br><span class="line">    <span class="attribute">width</span>:auto; </span><br><span class="line">    <span class="attribute">display</span>:block;</span><br><span class="line">    <span class="attribute">white-space</span>:pre-wrap;</span><br><span class="line">    <span class="attribute">word-wrap</span> : break-word ;</span><br><span class="line">    <span class="attribute">overflow</span>: hidden ;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><a target="_blank" rel="noopener" href="https://blog.csdn.net/qingyun0719/article/details/5629981">参考链接</a><br>或者：  </p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-class">.ui-jqgrid</span> <span class="selector-tag">tr</span><span class="selector-class">.jqgrow</span> <span class="selector-tag">td</span><span class="selector-pseudo">:nth-child</span>(<span class="number">6</span>) &#123;</span><br><span class="line">   <span class="attribute">white-space</span>: normal <span class="meta">!important</span>;</span><br><span class="line">   <span class="attribute">word-break</span>:break-all;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><a target="_blank" rel="noopener" href="https://blog.csdn.net/zhengxiangwen/article/details/9120215">参考链接</a>  </p>
<h3 id="5-js动态获取浏览器或页面等容器的宽高的方法大体有哪些："><a href="#5-js动态获取浏览器或页面等容器的宽高的方法大体有哪些：" class="headerlink" title="5.js动态获取浏览器或页面等容器的宽高的方法大体有哪些："></a>5.js动态获取浏览器或页面等容器的宽高的方法大体有哪些：</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">除去浏览器边框，标签栏等的宽度：document.documentElement.clientWidth</span><br><span class="line">除去浏览器边框，标签栏等的高度：document.documentElement.clientHeight  </span><br><span class="line">（以上用得最多）</span><br><span class="line">网页可见区域宽： document.body.clientWidth </span><br><span class="line">网页可见区域高： document.body.clientHeight </span><br><span class="line">网页可见区域宽： document.body.offsetWidth (包括边线的宽) </span><br><span class="line">网页可见区域高： document.body.offsetHeight (包括边线的高) </span><br><span class="line">网页正文全文宽： document.body.scrollWidth </span><br><span class="line">网页正文全文高： document.body.scrollHeight </span><br><span class="line">网页被卷去的高： document.body.scrollTop </span><br><span class="line">网页被卷去的左： document.body.scrollLeft </span><br><span class="line">网页正文部分上： window.screenTop </span><br><span class="line">网页正文部分左： window.screenLeft </span><br><span class="line">屏幕分辨率的高： window.screen.height </span><br><span class="line">屏幕分辨率的宽： window.screen.width </span><br><span class="line">屏幕可用工作区高度： window.screen.availHeight </span><br><span class="line">屏幕可用工作区宽度： window.screen.availWidth</span><br></pre></td></tr></table></figure>

<h3 id="6-div随着浏览器窗口大小变更，改变大小（resize）："><a href="#6-div随着浏览器窗口大小变更，改变大小（resize）：" class="headerlink" title="6.div随着浏览器窗口大小变更，改变大小（resize）："></a>6.div随着浏览器窗口大小变更，改变大小（resize）：</h3><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">&quot;resizediv&quot;</span> <span class="attr">align</span>=<span class="string">&quot;center&quot;</span> <span class="attr">style</span>=<span class="string">&quot;width: 500px;height: 200px;border: 1px solid black;margin: auto;&quot;</span>&gt;</span>這是一個測試<span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">    <span class="comment">&lt;!-- div设置 margin: auto; 可使其居中 --&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">&quot;jquery.min.js&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="javascript">        $(<span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span></span><br><span class="line"><span class="javascript">            $(<span class="built_in">window</span>).resize(<span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span></span><br><span class="line"><span class="javascript">                <span class="keyword">var</span> cliWidth = <span class="built_in">document</span>.documentElement.clientWidth;   <span class="comment">// 瀏覽器寬</span></span></span><br><span class="line"><span class="javascript">                <span class="keyword">var</span> cliHeight = <span class="built_in">document</span>.documentElement.clientHeight; <span class="comment">// 瀏覽器高</span></span></span><br><span class="line"><span class="javascript">                <span class="built_in">console</span>.log(cliWidth)</span></span><br><span class="line"><span class="javascript">                <span class="built_in">console</span>.log(cliHeight)</span></span><br><span class="line"><span class="javascript">                $(<span class="string">&#x27;#resizediv&#x27;</span>).css(<span class="string">&quot;width&quot;</span>, <span class="string">&quot;500px&quot;</span>);</span></span><br><span class="line"><span class="javascript">                $(<span class="string">&#x27;#resizediv&#x27;</span>).css(<span class="string">&quot;height&quot;</span>, <span class="string">&quot;200px&quot;</span>);</span></span><br><span class="line">            &#125;);</span><br><span class="line">        &#125;);</span><br><span class="line">    <span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line">或者使用CSS</span><br><span class="line"><span class="tag">&lt;<span class="name">head</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">&quot;UTF-8&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">title</span>&gt;</span>Document<span class="tag">&lt;/<span class="name">title</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">style</span>&gt;</span></span><br><span class="line">        #div1 &#123;</span><br><span class="line"><span class="css">            <span class="attribute">position</span>: absolute;</span></span><br><span class="line"><span class="css">            <span class="attribute">left</span>: <span class="number">250px</span>;    <span class="comment">/* left是width里减号后面的一半，才能居中 */</span></span></span><br><span class="line"><span class="css">            <span class="attribute">width</span>: <span class="built_in">calc</span>(<span class="number">100%</span> - <span class="number">500px</span>);</span></span><br><span class="line"><span class="css">            <span class="attribute">border</span>: <span class="number">1px</span> solid black;</span></span><br><span class="line"><span class="css">            <span class="attribute">background-color</span>: yellow;</span></span><br><span class="line"><span class="css">            <span class="attribute">padding</span>: <span class="number">5px</span>;</span></span><br><span class="line"><span class="css">            <span class="attribute">text-align</span>: center;</span></span><br><span class="line">        &#125;</span><br><span class="line">    <span class="tag">&lt;/<span class="name">style</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">head</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">p</span>&gt;</span>创建一个横跨屏幕的div，div 两边有 50px 的间隙：<span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">&quot;div1&quot;</span>&gt;</span>一些文本...<span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br></pre></td></tr></table></figure>

<h3 id="7-有趣的控制台短语："><a href="#7-有趣的控制台短语：" class="headerlink" title="7.有趣的控制台短语："></a>7.有趣的控制台短语：</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">console</span>.log(<span class="string">&quot;%c Be a great maker!&quot;</span>, <span class="string">&quot;font-size:50px;color:red;text-fill-color:red;-webkit-text-stroke: 1px black;&quot;</span>)</span><br></pre></td></tr></table></figure>
<h3 id="8-图片加载失败后，显示自定义的图片，HTML代码："><a href="#8-图片加载失败后，显示自定义的图片，HTML代码：" class="headerlink" title="8.图片加载失败后，显示自定义的图片，HTML代码："></a>8.图片加载失败后，显示自定义的图片，HTML代码：</h3><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;!DOCTYPE <span class="meta-keyword">html</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">html</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">head</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">&quot;UTF-8&quot;</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">title</span>&gt;</span><span class="tag">&lt;/<span class="name">title</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">head</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">img</span> <span class="attr">src</span>=<span class="string">&quot;error.jpg&quot;</span> <span class="attr">onerror</span>=<span class="string">&quot;whenError(this)&quot;</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="javascript">	<span class="function"><span class="keyword">function</span> <span class="title">whenError</span>(<span class="params">a</span>) </span>&#123;</span></span><br><span class="line"><span class="javascript">		a.onerror = <span class="literal">null</span>;</span></span><br><span class="line"><span class="javascript">		a.src = <span class="string">&#x27;http://avatar.csdn.net/1/E/E/1_qq_27080247.jpg&#x27;</span>;</span></span><br><span class="line"><span class="javascript">		<span class="built_in">console</span>.log(<span class="string">&#x27;图片出错的时候调用默认的图片&#x27;</span>);</span></span><br><span class="line">	&#125;</span><br><span class="line"><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h3 id="9-JS遍历字典："><a href="#9-JS遍历字典：" class="headerlink" title="9.JS遍历字典："></a>9.JS遍历字典：</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">test = &#123;<span class="string">&#x27;a&#x27;</span>: <span class="number">1</span>,<span class="string">&#x27;b&#x27;</span>: <span class="number">2</span>,<span class="string">&#x27;c&#x27;</span>:<span class="number">3</span>&#125;;</span><br><span class="line"><span class="keyword">for</span> (<span class="keyword">var</span> i <span class="keyword">in</span> test) &#123; </span><br><span class="line">    alert(i + <span class="string">&quot;: &quot;</span> + test[i]); </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="10-让页面上的字体不可选择，只需要在style里面添加一个属性：-webkit-user-select-none"><a href="#10-让页面上的字体不可选择，只需要在style里面添加一个属性：-webkit-user-select-none" class="headerlink" title="10.让页面上的字体不可选择，只需要在style里面添加一个属性：-webkit-user-select: none;"></a>10.让页面上的字体不可选择，只需要在style里面添加一个属性：<code>-webkit-user-select: none;</code></h3><h3 id="11-让-lt-textarea-gt-不可拉伸大小，添加style样式：resize-none"><a href="#11-让-lt-textarea-gt-不可拉伸大小，添加style样式：resize-none" class="headerlink" title="11.让&lt;textarea&gt;不可拉伸大小，添加style样式：resize:none;"></a>11.让&lt;textarea&gt;不可拉伸大小，添加style样式：<code>resize:none;</code></h3><h3 id="12-JS函数传递一个对象参数："><a href="#12-JS函数传递一个对象参数：" class="headerlink" title="12.JS函数传递一个对象参数："></a>12.JS函数传递一个对象参数：</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">object = &#123;<span class="string">&quot;id&quot;</span>: <span class="number">1</span>, <span class="string">&quot;text&quot;</span>: <span class="string">&quot;测试&quot;</span>,<span class="string">&quot;data&quot;</span>: <span class="string">&quot;这是一个测试&quot;</span>&#125;</span><br><span class="line"><span class="keyword">return</span> <span class="string">&quot;&lt;button class=&#x27;btn btn-primary btn-xs&#x27; onclick=&#x27;out_warehouse_sure(&quot;</span> + <span class="built_in">JSON</span>.stringify(object) + <span class="string">&quot;)&#x27;&gt;出庫&lt;/button&gt;&quot;</span>;</span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">out_warehouse_sure</span>(<span class="params">obj</span>) </span>&#123;</span><br><span class="line">    console.log(obj.text)    # 输出：&quot;测试&quot;</span><br><span class="line">    .....</span><br><span class="line">&#125;</span><br><span class="line">说明：先把对象参数转换成<span class="built_in">JSON</span>字符串，这样传过去的参数直接就是一个对象参数  </span><br></pre></td></tr></table></figure>
<h3 id="13-JS排序：根据数组中的对象的多个属性值排序，多条件排序："><a href="#13-JS排序：根据数组中的对象的多个属性值排序，多条件排序：" class="headerlink" title="13.JS排序：根据数组中的对象的多个属性值排序，多条件排序："></a>13.JS排序：根据数组中的对象的<strong>多个属性值排序，多条件排序</strong>：</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">&lt;script&gt;</span><br><span class="line">    <span class="keyword">var</span> arr = [</span><br><span class="line">        &#123;<span class="attr">area</span>:<span class="string">&#x27;成都&#x27;</span>,<span class="attr">location</span>:<span class="string">&#x27;D23-1.5F&#x27;</span>&#125;,</span><br><span class="line">        &#123;<span class="attr">area</span>:<span class="string">&#x27;龍華&#x27;</span>,<span class="attr">location</span>:<span class="string">&#x27;D5-1.5F&#x27;</span>&#125;,</span><br><span class="line">        &#123;<span class="attr">area</span>:<span class="string">&#x27;成都&#x27;</span>,<span class="attr">location</span>:<span class="string">&#x27;B25-3F&#x27;</span>&#125;,</span><br><span class="line">        &#123;<span class="attr">area</span>:<span class="string">&#x27;成都&#x27;</span>,<span class="attr">location</span>:<span class="string">&#x27;C23-3F&#x27;</span>&#125;,</span><br><span class="line">        &#123;<span class="attr">area</span>:<span class="string">&#x27;牧維&#x27;</span>,<span class="attr">location</span>:<span class="string">&#x27;A2-1.5F&#x27;</span>&#125;,</span><br><span class="line">        &#123;<span class="attr">area</span>:<span class="string">&#x27;成都&#x27;</span>,<span class="attr">location</span>:<span class="string">&#x27;C23-2F&#x27;</span>&#125;,</span><br><span class="line">        &#123;<span class="attr">area</span>:<span class="string">&#x27;觀蘭&#x27;</span>,<span class="attr">location</span>:<span class="string">&#x27;B7-1.5F&#x27;</span>&#125;,</span><br><span class="line">        &#123;<span class="attr">area</span>:<span class="string">&#x27;成都&#x27;</span>,<span class="attr">location</span>:<span class="string">&#x27;A25-3F&#x27;</span>&#125;,</span><br><span class="line">    ];</span><br><span class="line">    <span class="keyword">var</span> rs = arr.sort( <span class="function">(<span class="params">a, b</span>) =&gt;</span> &#123;    <span class="comment">//如果area相同，按照location的降序</span></span><br><span class="line">        <span class="keyword">if</span> (a.area == b.area) &#123;</span><br><span class="line">            <span class="keyword">return</span> (b.location &gt; a.location) - <span class="number">0.5</span></span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> (a.area &gt; b.area) - <span class="number">0.5</span></span><br><span class="line">    &#125;)</span><br><span class="line">    <span class="built_in">console</span>.log(rs);</span><br><span class="line">&lt;/script&gt;</span><br></pre></td></tr></table></figure>
<p><a target="_blank" rel="noopener" href="https://blog.csdn.net/m0_37885651/article/details/80016718">参考链接</a></p>
<p><strong>博客材料搜集</strong></p>
<h3 id="14-每日格言API及HTML代码："><a href="#14-每日格言API及HTML代码：" class="headerlink" title="14.每日格言API及HTML代码："></a>14.每日格言API及HTML代码：</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">&lt;script&gt;</span><br><span class="line">    $(<span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">        <span class="comment">// var pattern = GeoPattern.generate(&#x27;hui-zz&#x27; + Math.random()).color;</span></span><br><span class="line">        <span class="comment">// $(&#x27;#particles-js&#x27;).css(&#x27;background&#x27;, pattern);</span></span><br><span class="line">        <span class="comment">// $(&#x27;#particles-js&#x27;).css(&#x27;background-image&#x27;,&#x27;url(https://api.isoyu.com/bing_images.php)&#x27;);</span></span><br><span class="line">        <span class="built_in">document</span>.getElementById(<span class="string">&#x27;particles-js&#x27;</span>).style.cssText = <span class="string">&quot;background-image:url(https://api.isoyu.com/bing_images.php);&quot;</span>;</span><br><span class="line">        $.getJSON(<span class="string">&quot;https://api.ooopn.com/ciba/api.php&quot;</span>,</span><br><span class="line">            <span class="function"><span class="keyword">function</span> (<span class="params">data</span>) </span>&#123;</span><br><span class="line">                $(<span class="string">&quot;.user-details h1&quot;</span>).text(data[<span class="string">&quot;ciba&quot;</span>]);</span><br><span class="line">                $(<span class="string">&quot;.user-details p&quot;</span>).text(data[<span class="string">&quot;ciba-en&quot;</span>]);</span><br><span class="line">            &#125;);</span><br><span class="line">    &#125;);</span><br><span class="line">&lt;/script&gt;  </span><br></pre></td></tr></table></figure>
<p><a target="_blank" rel="noopener" href="https://hui-zz.github.io/RunAny">参考链接</a></p>
<h3 id="15-博客看板动画人物："><a href="#15-博客看板动画人物：" class="headerlink" title="15.博客看板动画人物："></a>15.博客看板动画人物：</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br></pre></td><td class="code"><pre><span class="line">动漫人物</span><br><span class="line">&lt;div id=<span class="string">&quot;live2d-widget&quot;</span>&gt;</span><br><span class="line">    &lt;canvas id=<span class="string">&quot;live2dcanvas&quot;</span> width=<span class="string">&quot;NaN&quot;</span> height=<span class="string">&quot;400&quot;</span> </span><br><span class="line">        style=<span class="string">&quot;position: fixed; width: 20%; opacity: 0.7; right: -20px; bottom: -20px; z-index: 99999; pointer-events: none;&quot;</span>&gt;</span><br><span class="line">    &lt;/canvas&gt;</span><br><span class="line">&lt;/div&gt;</span><br><span class="line">&lt;script src=<span class="string">&quot;https://eqcn.ajz.miesnfu.com/wp-content/plugins/wp-3d-pony/live2dw/lib/L2Dwidget.min.js&quot;</span>&gt;&lt;/script&gt;</span><br><span class="line">&lt;script&gt;</span><br><span class="line">    L2Dwidget.init(&#123;</span><br><span class="line">        <span class="string">&quot;model&quot;</span>: &#123;</span><br><span class="line">            <span class="comment">//jsonpath控制显示那个模型</span></span><br><span class="line">            jsonPath: <span class="string">&quot;https://unpkg.com/live2d-widget-model-shizuku@1.0.5/assets/shizuku.model.json&quot;</span>,</span><br><span class="line">            <span class="string">&quot;scale&quot;</span>: <span class="number">1</span></span><br><span class="line">        &#125;,</span><br><span class="line">        <span class="string">&quot;display&quot;</span>: &#123;</span><br><span class="line">            <span class="string">&quot;position&quot;</span>: <span class="string">&quot;right&quot;</span>, <span class="comment">//看板娘的表现位置</span></span><br><span class="line">            <span class="string">&quot;width&quot;</span>: <span class="string">&quot;20%&quot;</span>,  <span class="comment">//宽度</span></span><br><span class="line">            <span class="string">&quot;height&quot;</span>: <span class="number">200</span>, <span class="comment">//高度</span></span><br><span class="line">            <span class="string">&quot;hOffset&quot;</span>: -<span class="number">20</span>,</span><br><span class="line">            <span class="string">&quot;vOffset&quot;</span>: -<span class="number">20</span></span><br><span class="line">        &#125;,</span><br><span class="line">        <span class="string">&quot;mobile&quot;</span>: &#123;</span><br><span class="line">            <span class="string">&quot;show&quot;</span>: <span class="literal">true</span>,</span><br><span class="line">            <span class="string">&quot;scale&quot;</span>: <span class="number">0.5</span></span><br><span class="line">        &#125;,</span><br><span class="line">        <span class="string">&quot;react&quot;</span>: &#123;</span><br><span class="line">            <span class="string">&quot;opacityDefault&quot;</span>: <span class="number">0.7</span>,</span><br><span class="line">            <span class="string">&quot;opacityOnHover&quot;</span>: <span class="number">0.2</span></span><br><span class="line">        &#125;</span><br><span class="line">    &#125;);</span><br><span class="line">&lt;/script&gt;  </span><br><span class="line">宠物猫  </span><br><span class="line">&lt;div id=<span class="string">&quot;live2d-widget&quot;</span>&gt;</span><br><span class="line">    &lt;canvas id=<span class="string">&quot;live2dcanvas&quot;</span> width=<span class="string">&quot;NaN&quot;</span> height=<span class="string">&quot;400&quot;</span></span><br><span class="line">        style=<span class="string">&quot;position: fixed; width: 20%; opacity: 0.7; right: -20px; bottom: -20px; z-index: 99999; pointer-events: none;&quot;</span>&gt;</span><br><span class="line">    &lt;/canvas&gt;</span><br><span class="line">&lt;/div&gt;</span><br><span class="line">&lt;script src=<span class="string">&quot;https://eqcn.ajz.miesnfu.com/wp-content/plugins/wp-3d-pony/live2dw/lib/L2Dwidget.min.js&quot;</span>&gt;&lt;/script&gt;</span><br><span class="line">&lt;script&gt;</span><br><span class="line">    L2Dwidget.init(&#123;</span><br><span class="line">        <span class="string">&quot;model&quot;</span>: &#123;</span><br><span class="line">            <span class="comment">//jsonpath控制显示那个模型</span></span><br><span class="line">            jsonPath: <span class="string">&quot;https://unpkg.com/live2d-widget-model-tororo@1.0.5/assets/tororo.model.json&quot;</span>,</span><br><span class="line">            <span class="string">&quot;scale&quot;</span>: <span class="number">1</span></span><br><span class="line">        &#125;,</span><br><span class="line">        <span class="string">&quot;display&quot;</span>: &#123;</span><br><span class="line">            <span class="string">&quot;position&quot;</span>: <span class="string">&quot;right&quot;</span>, <span class="comment">//看板娘的表现位置</span></span><br><span class="line">            <span class="string">&quot;width&quot;</span>: <span class="string">&quot;20%&quot;</span>,  <span class="comment">//宽度</span></span><br><span class="line">            <span class="string">&quot;height&quot;</span>: <span class="number">200</span>, <span class="comment">//高度</span></span><br><span class="line">            <span class="string">&quot;hOffset&quot;</span>: -<span class="number">20</span>,</span><br><span class="line">            <span class="string">&quot;vOffset&quot;</span>: -<span class="number">20</span></span><br><span class="line">        &#125;,</span><br><span class="line">        <span class="string">&quot;mobile&quot;</span>: &#123;</span><br><span class="line">            <span class="string">&quot;show&quot;</span>: <span class="literal">true</span>,</span><br><span class="line">            <span class="string">&quot;scale&quot;</span>: <span class="number">0.5</span></span><br><span class="line">        &#125;,</span><br><span class="line">        <span class="string">&quot;react&quot;</span>: &#123;</span><br><span class="line">            <span class="string">&quot;opacityDefault&quot;</span>: <span class="number">0.7</span>,</span><br><span class="line">            <span class="string">&quot;opacityOnHover&quot;</span>: <span class="number">0.2</span></span><br><span class="line">        &#125;</span><br><span class="line">    &#125;);</span><br><span class="line">&lt;/script&gt;</span><br></pre></td></tr></table></figure>
<h3 id="16-表格内容自动滚动"><a href="#16-表格内容自动滚动" class="headerlink" title="16.表格内容自动滚动"></a>16.表格内容自动滚动</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//javascript原生自动滚动</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">startmarquee</span>(<span class="params">lh, speed, delay, marqueeObj</span>) </span>&#123;  <span class="comment">//lh---每行列表的高度，speed---滚动的速度，delay---间隔多久滚动一次,marqueeObj---需要实现这个效果的id</span></span><br><span class="line">    <span class="keyword">var</span> p = <span class="literal">false</span>;</span><br><span class="line">    <span class="keyword">var</span> t;</span><br><span class="line">    <span class="keyword">var</span> o = <span class="built_in">document</span>.getElementById(marqueeObj);</span><br><span class="line">    o.innerHTML += o.innerHTML;</span><br><span class="line">    o.style.marginTop = <span class="number">0</span>;</span><br><span class="line">    o.onmouseover = <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123; p = <span class="literal">true</span>; &#125; <span class="comment">//鼠标移入，停止滚动</span></span><br><span class="line">    o.onmouseout = <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123; p = <span class="literal">false</span>; &#125;<span class="comment">//鼠标移出，继续滚动</span></span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">function</span> <span class="title">start</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">        t = <span class="built_in">setInterval</span>(scrolling, speed); <span class="comment">//定时器，自动滚动</span></span><br><span class="line">        <span class="keyword">if</span> (!p) o.style.marginTop = <span class="built_in">parseInt</span>(o.style.marginTop) - <span class="number">1</span> + <span class="string">&quot;px&quot;</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">function</span> <span class="title">scrolling</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">        <span class="keyword">if</span> (<span class="built_in">parseInt</span>(o.style.marginTop) % lh != <span class="number">0</span>) &#123;</span><br><span class="line">            o.style.marginTop = <span class="built_in">parseInt</span>(o.style.marginTop) - <span class="number">1</span> + <span class="string">&quot;px&quot;</span>;</span><br><span class="line">            <span class="keyword">if</span> (<span class="built_in">Math</span>.abs(<span class="built_in">parseInt</span>(o.style.marginTop)) &gt;= o.scrollHeight / <span class="number">2</span>) o.style.marginTop = <span class="number">0</span>;</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            <span class="built_in">clearInterval</span>(t);</span><br><span class="line">            <span class="built_in">setTimeout</span>(start, delay);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="built_in">setTimeout</span>(start, delay);</span><br><span class="line">&#125;</span><br><span class="line">startmarquee(<span class="number">48</span>, <span class="number">35</span>, <span class="number">0</span>, <span class="string">&quot;goods-info&quot;</span>); <span class="comment">//引用函数</span></span><br></pre></td></tr></table></figure>
<h3 id="17-JS深拷贝"><a href="#17-JS深拷贝" class="headerlink" title="17.JS深拷贝"></a>17.JS深拷贝</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> obj1 = &#123;<span class="attr">a</span>: <span class="number">1</span>, <span class="attr">b</span>: <span class="number">2</span>, <span class="attr">c</span>: <span class="number">3</span>&#125;</span><br><span class="line"><span class="keyword">let</span> objString = <span class="built_in">JSON</span>.stringify(obj1)</span><br><span class="line"><span class="keyword">let</span> obj2 = <span class="built_in">JSON</span>.parse(objString)</span><br><span class="line">obj2.a = <span class="number">5</span>;</span><br><span class="line"><span class="built_in">console</span>.log(obj1.a);  <span class="comment">// 1</span></span><br><span class="line"><span class="built_in">console</span>.log(obj2.a); <span class="comment">// 5</span></span><br></pre></td></tr></table></figure>
<h3 id="18-JS对数组中的对象去重"><a href="#18-JS对数组中的对象去重" class="headerlink" title="18.JS对数组中的对象去重"></a>18.JS对数组中的对象去重</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> arr = [&#123;</span><br><span class="line">  key: <span class="string">&#x27;01&#x27;</span>,</span><br><span class="line">  value: <span class="string">&#x27;乐乐&#x27;</span></span><br><span class="line">&#125;, &#123;</span><br><span class="line">  key: <span class="string">&#x27;02&#x27;</span>,</span><br><span class="line">  value: <span class="string">&#x27;博博&#x27;</span></span><br><span class="line">&#125;, &#123;</span><br><span class="line">  key: <span class="string">&#x27;03&#x27;</span>,</span><br><span class="line">  value: <span class="string">&#x27;淘淘&#x27;</span></span><br><span class="line">&#125;, &#123;</span><br><span class="line">  key: <span class="string">&#x27;04&#x27;</span>,</span><br><span class="line">  value: <span class="string">&#x27;哈哈&#x27;</span></span><br><span class="line">&#125;, &#123;</span><br><span class="line">  key: <span class="string">&#x27;01&#x27;</span>,</span><br><span class="line">  value: <span class="string">&#x27;乐乐&#x27;</span></span><br><span class="line">&#125;];</span><br><span class="line"><span class="comment">// 方法1：利用对象访问属性的方法，判断对象中是否存在key</span></span><br><span class="line"><span class="keyword">var</span> result = [];</span><br><span class="line"><span class="keyword">var</span> obj = &#123;&#125;;</span><br><span class="line"><span class="keyword">for</span> (<span class="keyword">var</span> i = <span class="number">0</span>; i &lt; arr.length; i++) &#123;</span><br><span class="line">  <span class="keyword">if</span> (!obj[arr[i].key]) &#123;</span><br><span class="line">    result.push(arr[i]);</span><br><span class="line">    obj[arr[i].key] = <span class="literal">true</span>;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="built_in">console</span>.log(result); <span class="comment">// [&#123;key: &quot;01&quot;, value: &quot;乐乐&quot;&#125;,&#123;key: &quot;02&quot;, value: &quot;博博&quot;&#125;,&#123;key: &quot;03&quot;, value: &quot;淘淘&quot;&#125;,&#123;key: &quot;04&quot;, value: &quot;哈哈&quot;&#125;]</span></span><br><span class="line"><span class="comment">// 方法2：利用reduce方法遍历数组,reduce第一个参数是遍历需要执行的函数，第二个参数是item的初始值</span></span><br><span class="line"><span class="keyword">var</span> obj = &#123;&#125;;</span><br><span class="line">arr = arr.reduce(<span class="function"><span class="keyword">function</span> (<span class="params">item, next</span>) </span>&#123;</span><br><span class="line">  obj[next.key] ? <span class="string">&#x27;&#x27;</span> : obj[next.key] = <span class="literal">true</span> &amp;&amp; item.push(next);</span><br><span class="line">  <span class="keyword">return</span> item;</span><br><span class="line">&#125;, []);</span><br><span class="line"><span class="built_in">console</span>.log(arr); <span class="comment">// [&#123;key: &quot;01&quot;, value: &quot;乐乐&quot;&#125;,&#123;key: &quot;02&quot;, value: &quot;博博&quot;&#125;,&#123;key: &quot;03&quot;, value: &quot;淘淘&quot;&#125;,&#123;key: &quot;04&quot;, value: &quot;哈哈&quot;&#125;]</span></span><br></pre></td></tr></table></figure>

<h3 id="JS将两个数组合并"><a href="#JS将两个数组合并" class="headerlink" title="JS将两个数组合并"></a>JS将两个数组合并</h3><h4 id="方法一"><a href="#方法一" class="headerlink" title="方法一"></a>方法一</h4><p><strong>使用concat</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> a = [<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>];</span><br><span class="line"><span class="keyword">var</span> b = [<span class="number">4</span>,<span class="number">5</span>,<span class="number">6</span>];</span><br><span class="line"><span class="keyword">var</span> c = a.concat(b);</span><br><span class="line"></span><br><span class="line"><span class="comment">//c=[1,2,3,4,5,6];</span></span><br></pre></td></tr></table></figure>

<h4 id="方法二"><a href="#方法二" class="headerlink" title="方法二"></a>方法二</h4><p><strong>使用循环</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span>(<span class="keyword">let</span> i <span class="keyword">in</span> b)&#123;</span><br><span class="line">　　a.push(b[i])</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="方法三"><a href="#方法三" class="headerlink" title="方法三"></a>方法三</h4><p><strong>使用apply</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">a.push.apply(a,b);</span><br></pre></td></tr></table></figure>

<h4 id="方法四"><a href="#方法四" class="headerlink" title="方法四"></a>方法四</h4><p><strong>使用push</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">a.push(...b)	<span class="comment">// ...的作用是将一个数组转为用逗号分隔的参数序列</span></span><br></pre></td></tr></table></figure>

<h4 id="建议"><a href="#建议" class="headerlink" title="建议"></a>建议</h4><p>在合并数组的时候，可以首先判断数组的大小，以大的合并小的显然速度会快一些</p>
<p>如果不希望改变数组的话，建议使用concat</p>
</article><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/JS%E9%9A%8F%E7%AC%94/">JS随笔</a></div><div class="post_share"><div class="social-share" data-image="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2021/04/16/Hello-world/"><img class="prev-cover" data-lazy-src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">Hello World</div></div></a></div><div class="next-post pull-right"><a href="/2021/04/16/MySQL%E6%9F%A5%E9%87%8D%E3%80%81%E5%8E%BB%E9%87%8D%E3%80%81%E5%88%A0%E9%87%8D/"><img class="next-cover" data-lazy-src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">Mysql查重、去重、删重</div></div></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="card-info-avatar is-center"><img class="avatar-img" data-lazy-src="/img/avatar/avatar.png" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/><div class="author-info__name">MrLee</div><div class="author-info__description">Try harder</div></div><div class="card-info-data"><div class="card-info-data-item is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">34</div></a></div><div class="card-info-data-item is-center"><a href="/tags/"><div class="headline">标签</div><div class="length-num">35</div></a></div><div class="card-info-data-item is-center"><a href="/categories/"><div class="headline">分类</div><div class="length-num">14</div></a></div></div><a class="button--animated" id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/MrLeeqi/"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/MrLeeqi/" target="_blank" title="Github"><i class="fab fa-github"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn card-announcement-animation"></i><span>公告</span></div><div class="announcement_content">文章会不定期的更新！！！<br>如有疑问，请联系QQ：1012274457</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#JS"><span class="toc-number">1.</span> <span class="toc-text">JS</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-%E5%9C%A8%E5%BA%94%E7%94%A8%E4%B8%AD%E6%B7%BB%E5%8A%A0-%E5%BD%93%E5%89%8D%E6%97%B6%E9%97%B4-%E6%96%B9%E6%B3%95"><span class="toc-number">1.1.</span> <span class="toc-text">1.在应用中添加 当前时间 方法</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-%E6%97%B6%E9%97%B4%E5%80%92%E8%AE%A1%E6%97%B6%E5%8A%9F%E8%83%BD%EF%BC%9A"><span class="toc-number">1.2.</span> <span class="toc-text">2.时间倒计时功能：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-%E6%95%B0%E5%AD%97%E8%AE%A1%E6%97%B6%E5%8A%9F%E8%83%BD%EF%BC%9A"><span class="toc-number">1.3.</span> <span class="toc-text">3.数字计时功能：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-%E9%81%87%E5%88%B0%E4%B8%80%E8%A1%8C%E5%AD%97%E6%95%B0%E5%A4%AA%E5%A4%9A%E6%98%BE%E7%A4%BA%E4%B8%8D%E5%AE%8C%EF%BC%8C%E5%8F%AF%E4%BB%A5%E4%BD%BF%E7%94%A8%E4%BB%A5%E4%B8%8B%E6%96%B9%E6%B3%95%EF%BC%9A"><span class="toc-number">1.4.</span> <span class="toc-text">4.遇到一行字数太多显示不完，可以使用以下方法：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-js%E5%8A%A8%E6%80%81%E8%8E%B7%E5%8F%96%E6%B5%8F%E8%A7%88%E5%99%A8%E6%88%96%E9%A1%B5%E9%9D%A2%E7%AD%89%E5%AE%B9%E5%99%A8%E7%9A%84%E5%AE%BD%E9%AB%98%E7%9A%84%E6%96%B9%E6%B3%95%E5%A4%A7%E4%BD%93%E6%9C%89%E5%93%AA%E4%BA%9B%EF%BC%9A"><span class="toc-number">1.5.</span> <span class="toc-text">5.js动态获取浏览器或页面等容器的宽高的方法大体有哪些：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#6-div%E9%9A%8F%E7%9D%80%E6%B5%8F%E8%A7%88%E5%99%A8%E7%AA%97%E5%8F%A3%E5%A4%A7%E5%B0%8F%E5%8F%98%E6%9B%B4%EF%BC%8C%E6%94%B9%E5%8F%98%E5%A4%A7%E5%B0%8F%EF%BC%88resize%EF%BC%89%EF%BC%9A"><span class="toc-number">1.6.</span> <span class="toc-text">6.div随着浏览器窗口大小变更，改变大小（resize）：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#7-%E6%9C%89%E8%B6%A3%E7%9A%84%E6%8E%A7%E5%88%B6%E5%8F%B0%E7%9F%AD%E8%AF%AD%EF%BC%9A"><span class="toc-number">1.7.</span> <span class="toc-text">7.有趣的控制台短语：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#8-%E5%9B%BE%E7%89%87%E5%8A%A0%E8%BD%BD%E5%A4%B1%E8%B4%A5%E5%90%8E%EF%BC%8C%E6%98%BE%E7%A4%BA%E8%87%AA%E5%AE%9A%E4%B9%89%E7%9A%84%E5%9B%BE%E7%89%87%EF%BC%8CHTML%E4%BB%A3%E7%A0%81%EF%BC%9A"><span class="toc-number">1.8.</span> <span class="toc-text">8.图片加载失败后，显示自定义的图片，HTML代码：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#9-JS%E9%81%8D%E5%8E%86%E5%AD%97%E5%85%B8%EF%BC%9A"><span class="toc-number">1.9.</span> <span class="toc-text">9.JS遍历字典：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#10-%E8%AE%A9%E9%A1%B5%E9%9D%A2%E4%B8%8A%E7%9A%84%E5%AD%97%E4%BD%93%E4%B8%8D%E5%8F%AF%E9%80%89%E6%8B%A9%EF%BC%8C%E5%8F%AA%E9%9C%80%E8%A6%81%E5%9C%A8style%E9%87%8C%E9%9D%A2%E6%B7%BB%E5%8A%A0%E4%B8%80%E4%B8%AA%E5%B1%9E%E6%80%A7%EF%BC%9A-webkit-user-select-none"><span class="toc-number">1.10.</span> <span class="toc-text">10.让页面上的字体不可选择，只需要在style里面添加一个属性：-webkit-user-select: none;</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#11-%E8%AE%A9-lt-textarea-gt-%E4%B8%8D%E5%8F%AF%E6%8B%89%E4%BC%B8%E5%A4%A7%E5%B0%8F%EF%BC%8C%E6%B7%BB%E5%8A%A0style%E6%A0%B7%E5%BC%8F%EF%BC%9Aresize-none"><span class="toc-number">1.11.</span> <span class="toc-text">11.让&lt;textarea&gt;不可拉伸大小，添加style样式：resize:none;</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#12-JS%E5%87%BD%E6%95%B0%E4%BC%A0%E9%80%92%E4%B8%80%E4%B8%AA%E5%AF%B9%E8%B1%A1%E5%8F%82%E6%95%B0%EF%BC%9A"><span class="toc-number">1.12.</span> <span class="toc-text">12.JS函数传递一个对象参数：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#13-JS%E6%8E%92%E5%BA%8F%EF%BC%9A%E6%A0%B9%E6%8D%AE%E6%95%B0%E7%BB%84%E4%B8%AD%E7%9A%84%E5%AF%B9%E8%B1%A1%E7%9A%84%E5%A4%9A%E4%B8%AA%E5%B1%9E%E6%80%A7%E5%80%BC%E6%8E%92%E5%BA%8F%EF%BC%8C%E5%A4%9A%E6%9D%A1%E4%BB%B6%E6%8E%92%E5%BA%8F%EF%BC%9A"><span class="toc-number">1.13.</span> <span class="toc-text">13.JS排序：根据数组中的对象的多个属性值排序，多条件排序：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#14-%E6%AF%8F%E6%97%A5%E6%A0%BC%E8%A8%80API%E5%8F%8AHTML%E4%BB%A3%E7%A0%81%EF%BC%9A"><span class="toc-number">1.14.</span> <span class="toc-text">14.每日格言API及HTML代码：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#15-%E5%8D%9A%E5%AE%A2%E7%9C%8B%E6%9D%BF%E5%8A%A8%E7%94%BB%E4%BA%BA%E7%89%A9%EF%BC%9A"><span class="toc-number">1.15.</span> <span class="toc-text">15.博客看板动画人物：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#16-%E8%A1%A8%E6%A0%BC%E5%86%85%E5%AE%B9%E8%87%AA%E5%8A%A8%E6%BB%9A%E5%8A%A8"><span class="toc-number">1.16.</span> <span class="toc-text">16.表格内容自动滚动</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#17-JS%E6%B7%B1%E6%8B%B7%E8%B4%9D"><span class="toc-number">1.17.</span> <span class="toc-text">17.JS深拷贝</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#18-JS%E5%AF%B9%E6%95%B0%E7%BB%84%E4%B8%AD%E7%9A%84%E5%AF%B9%E8%B1%A1%E5%8E%BB%E9%87%8D"><span class="toc-number">1.18.</span> <span class="toc-text">18.JS对数组中的对象去重</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#JS%E5%B0%86%E4%B8%A4%E4%B8%AA%E6%95%B0%E7%BB%84%E5%90%88%E5%B9%B6"><span class="toc-number">1.19.</span> <span class="toc-text">JS将两个数组合并</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%96%B9%E6%B3%95%E4%B8%80"><span class="toc-number">1.19.1.</span> <span class="toc-text">方法一</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%96%B9%E6%B3%95%E4%BA%8C"><span class="toc-number">1.19.2.</span> <span class="toc-text">方法二</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%96%B9%E6%B3%95%E4%B8%89"><span class="toc-number">1.19.3.</span> <span class="toc-text">方法三</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%96%B9%E6%B3%95%E5%9B%9B"><span class="toc-number">1.19.4.</span> <span class="toc-text">方法四</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%BB%BA%E8%AE%AE"><span class="toc-number">1.19.5.</span> <span class="toc-text">建议</span></a></li></ol></li></ol></li></ol></div></div></div></div></main><footer id="footer" style="background-image: url('https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg')"><div id="footer-wrap"><div class="copyright">&copy;2021 By MrLee</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div><div class="footer_custom_text">Hi, welcome to my <a href="https://amasmrlee.gitee.io">blog</a>!</div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="font-plus" type="button" title="放大字体"><i class="fas fa-plus"></i></button><button id="font-minus" type="button" title="缩小字体"><i class="fas fa-minus"></i></button><button id="translateLink" type="button" title="简繁转换">繁</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><div class="search-dialog__title" id="local-search-title">本地搜索</div><div id="local-input-panel"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div></div><hr/><div id="local-search-results"></div><span class="search-close-button"><i class="fas fa-times"></i></span></div><div id="search-mask"></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="/js/tw_cn.js"></script><script src="https://cdn.jsdelivr.net/npm/medium-zoom/dist/medium-zoom.min.js"></script><script src="https://cdn.jsdelivr.net/npm/instant.page/instantpage.min.js" type="module"></script><script src="https://cdn.jsdelivr.net/npm/vanilla-lazyload/dist/lazyload.iife.min.js"></script><script src="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.js"></script><script>function panguFn () {
  if (typeof pangu === 'object') pangu.autoSpacingPage()
  else {
    getScript('https://cdn.jsdelivr.net/npm/pangu/dist/browser/pangu.min.js')
      .then(() => {
        pangu.autoSpacingPage()
      })
  }
}

function panguInit () {
  if (true){
    GLOBAL_CONFIG_SITE.isPost && panguFn()
  } else {
    panguFn()
  }
}

document.addEventListener('DOMContentLoaded', panguInit)</script><script src="/js/search/local-search.js"></script><script>var preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',preloader.endLoading())</script><div class="js-pjax"></div><script defer="defer" id="ribbon" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-ribbon.min.js" size="150" alpha="0.6" zIndex="-1" mobile="true" data-click="true"></script><script id="canvas_nest" defer="defer" color="0,0,255" opacity="0.7" zIndex="-1" count="99" mobile="true" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-nest.min.js"></script><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/activate-power-mode.min.js"></script><script>POWERMODE.colorful = true;
POWERMODE.shake = true;
POWERMODE.mobile = false;
document.body.addEventListener('input', POWERMODE);
</script><script id="click-heart" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/click-heart.min.js" async="async" mobile="true"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>